import { defineStore } from "pinia";
import axios from "../axios";

const goodsStore = defineStore({
    id: 'goodsStore',

    state: () => ({
        GoodsList: [],
        goodsDetail: []
    }),

    actions: { 

        // 获取商品列表
        homeGoodsList() { 
            const thiss = this
            return new Promise ((reslove, reject) => { 
                axios.post('store.product/list').then (res => { 
                    thiss.GoodsList = res.data.data
                    reslove(res.data)
                }).catch(err => { 
                    reject(err.data)
                })
            })
        },

        // 获取商品详情
        getGoodsDetail(data) { 
            const thiss = this
            return new Promise ((reslove, reject) => { 
                axios.get('store.product/details', {
                    params: data
                }).then(res => { 
                    thiss.goodsDetail = res.data
                    reslove(res.data)
                }).catch(err => { 
                    reject(err.data)
                })
            })
        },

        // 获取盲盒列表
        getBlindBoxList (data) { 
            return new Promise((reslove, reject) => { 
                axios.get('goods_blind_box', { 
                    params: data
                }).then(res => { 
                    reslove(res.data)
                }).catch(res => { 
                    reject(res.data)
                })
            })
        }
    }
})

export default goodsStore